Online-Academy
Look, Read, Understand, Apply

Questions - Basics

  • Make a class person with properties: name, age methods to set member variables.
  • Make base class Vehicle with properties: type, color. Extends Vehicle with car and truck. Assume your own assumptions about properties (attributes) and methods of car and truck.
  • WRite a program to check if a number is prime or not
  • Write a program to generate series: 1+5+9+13+17+..
  • WRite a program to compare two strings.
  • How will you use package? Explain with example.
  • What are the benefits of inheritance?
  • What is interface?
  • Explain use of keywords: static, final, public, extends, implements.
  • What is use of super keyword()?
  • Explain function overloading with example.
  • explain function overriding with example
  • What are dynamic and static polymorphism?
  • Write a program to add to numbers.
  • Write a program to check if a number is even or odd.
  • Make a class named box with length, breadth as member variables and method to set member variables and to calculate area of the box.
  • Make a class numbers with overloaded add methods, one with two parameters and another with three parameters.
  • Create a class Rectangle with data members: length and breadth. • Create two constructors: one default and one parameterized. • Include a method to calculate the area. • Demonstrate constructor overloading using two objects.
  • Write a Java program using switch-case to perform a calculator operation (addition, subtraction, multiplication, division) based on user choice.
  • Make a class circle with member variables radius and pi, and constructors initialize radius and pi, and method to display values of radius and pi.
  • Write a Java program to take 5 numbers in an array and calculate their average.
  • Make a class person with name and age as attributes and methods to set and display values of member variables.
  • Create a class Counter with a static variable count that increments for each object created.
  • Show how many objects were created by displaying count in the main method.
  • Create a class BankAccount with private fields: • accountNumber (String) • balance (double) Provide getter and setter methods for each field. Ensure that balance cannot be set to a negative number.
  • Make a student class with name as a member variable, student has a constructor to set value for variable name and method to display value of variable name. Then make class bimstudent which inherits student class, bimstudent class has gender as member variable, it has constructor to initialize name and gender and to display name and gender.
  • Write a program to display sum of two numbers provided as parameters to main method.
  • Write a program to display length of three strings provided as parameters to main method.
  • Write a program to check if string provided as parameter to main method has any vowel or not.
  • Create a base class Employee with attributes: name and salary. Create a derived class Manager that has an extra attribute: department. Demonstrate single inheritance and write a method to display all details.
  • Create a class Animal with a method makeSound(). Create subclasses Dog and Cat that override makeSound(). Demonstrate runtime polymorphism by calling makeSound() using a superclass reference.
  • Create an abstract class Shape with an abstract method calculateArea().
  • Create subclasses Circle and Rectangle that implement this method.
  • Create an interface Vehicle with a method move(). Implement this interface in classes Car and Bike, and override the move() method.
  • Define containership. Make classes wheel and engine, wheel with member variables diameter, and price, and engine has capacity as member variable. Then make class vehicle with wheel object and engine object as members, vehicle has methods to set diameter, price and capacity and to display values of these member variables. Then make a driver class vehicle_demo with main method where object of vehicle is created and its methods are used.
  • What is package and what its use? How is package used in Java, Explain with an example.